package com.pn.mapper;

import com.github.pagehelper.Page;
import com.pn.entity.InStore;
import com.pn.entity.Purchase;
import org.apache.ibatis.annotations.*;

import java.time.LocalDateTime;

@Mapper
public interface PurchaseMapper {

    //添加采购单
    @Insert("insert into buy_list values(null,#{productId},#{storeId},#{buyNum}" +
            ",null,now(),#{supplyId},#{placeId},#{buyUser},#{phone},0) ")
    int insertPurchase(Purchase purchase);

    //显示采购列表
    Page<Purchase> purchasePageList(Purchase purchase);

    //删除采购单
    @Delete("delete from buy_list where buy_id = #{buyId}")
    int purchaseRemoveByid(Integer buyId);

    //修改采购单
    int purchaseUpdateByid(Purchase purchase);

    //根据buyId修改is_id为1
    @Update("update buy_list set is_in = 1 where buy_id = #{buyId}")
    void updateIsInByid(Integer buyId);

    //生成入库单
    @Insert("insert into in_store values(null,#{storeId},#{productId},#{inNum},#{createBy},now(),#{isIn})")
    int insertInStore(InStore inStore);

    //统计今日采购量
    @Select("select sum(fact_buy_num) from buy_list where buy_time >= #{param1} and buy_time <= #{param2}")
    Integer todayPurchase(LocalDateTime begin, LocalDateTime end);
}
